<?php
include("init.php");

$action =  isset($_GET['action']) ? $_GET['action'] : "";
$page = isset($_POST['current']) ? $_POST['current'] : 1;
$limit = isset($_POST['limit']) ? $_POST['limit'] : 10;
$food_id =  isset($_GET['food_id']) ? $_GET['food_id'] : 0;

$art_id=isset($_GET['art_id']) ? $_GET['art_id']:0;

$artcate_id=isset($_GET['artcate_id']) ? $_GET['artcate_id']:0;

$fcate_id=isset($_GET["fcate_id"]) ? $_GET["fcate_id"]:0;

$shop_id=isset($_GET["shop_id"]) ? $_GET["shop_id"]:0;

$region_id=isset($_GET["region_id"]) ? $_GET["region_id"] :0;

$link_id=isset($_GET["link_id"]) ? $_GET["link_id"]:0;

$company_id=isset($_GET["company_id"]) ? $_GET["company_id"]:0;

$admin_id=isset($_GET["admin_id"]) ? $_GET["admin_id"] : 0;


if($action == "system")
{
    $system = array(
        "PHP_VERSION"=>PHP_VERSION,
        "PHP_OS"=>PHP_OS,
        "mysql_version"=>mysqli_get_client_info($conn)
    );

    echo json_encode($system);
    exit;
}else if($action == "system_edit"){ //修改系统配置

    if($_FILES && $conf_img = upload_file("file","../Assets/uploads/"))
    {
        echo json_encode(array("conf_img"=>$conf_img));
        exit;
    }

    if($_POST)
    {
        $data = array(
            "conf_name"=>$_POST['conf_name'],
            "conf_content"=>$_POST['conf_content'],
            "conf_copyright"=>$_POST['conf_copyright'],
            "conf_email"=>$_POST['conf_email'],
            "conf_phone"=>$_POST['conf_phone']
        );

        if(isset($_POST['conf_img']) && !empty($_POST['conf_img']))
        {
            $data['conf_img'] = $_POST['conf_img'];
        }

        $affect_id = update("{$pre_}config",$data,"conf_id = 1");

        if($affect_id)  //修改成功
        {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }
    }
    $sql = "SELECT * FROM {$pre_}config WHERE conf_id = 1";
    $system = getOne($sql);
    echo json_encode($system);
    exit;
}else if($action == "food_count"){  //食品总数
      $sql = "SELECT COUNT(*) AS c FROM {$pre_}food";
      $food_count = getOne($sql);
      echo json_encode($food_count);
      exit;
}else if($action == "food_list"){ //食品数据
    $start = ($page-1)*$limit;
    $sql = "SELECT * FROM {$pre_}food AS food LEFT JOIN {$pre_}catefood AS cate ON food.fcate_id = cate.fcate_id ORDER BY food.food_id DESC LIMIT $start,$limit";
    $food_list = getAll($sql);
    echo json_encode($food_list);
    exit;
}else if($action == "food_cate"){

    $sql = "SELECT * FROM {$pre_}catefood";
    $cate_list = getAll($sql);
    echo json_encode($cate_list);
    exit;


}else if($action == "food_add"){

    if($_FILES && $_FILES['file']['error'] == 0 && $food_img = upload_file("file","../Assets/uploads/")){
        echo json_encode(array("food_img"=>$food_img));
        exit;
    }

    // 通过  saveForm()方法提交过来的 数据

    if($_POST){
        $data = array(
            "food_name"=>$_POST['food_name'],
            "food_price"=>$_POST['food_price'],
            "food_time"=>strtotime($_POST['food_time']),
            "food_content"=>$_POST['food_content'],
            "fcate_id"=>$_POST['fcate_id'],
        );

        if(isset($_POST['food_img']) && !empty($_POST['food_img'])){
            $data['food_img'] = $_POST['food_img'];
        }

        $insert_id = insert("{$pre_}food",$data);
        if($insert_id)  //修改成功
        {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }


    }


}else if($action == "food_detail"){
    $sql = "SELECT * FROM {$pre_}food AS food LEFT JOIN {$pre_}catefood AS cate ON food.fcate_id = cate.fcate_id WHERE food.food_id = $food_id";
    $food_detail = getOne($sql);
    echo json_encode($food_detail);
    exit;

}else if($action == "food_edit"){
     // 修改图片
     if($_FILES && $_FILES['file']['error'] == 0 && $food_img = upload_file("file","../Assets/uploads/")){
         echo json_encode(array("food_img"=>$food_img));
         exit;
     }

     if($_POST)
     {
         $data = array(
             "food_name"=>$_POST['food_name'],
             "food_price"=>$_POST['food_price'],
             "food_time"=>strtotime($_POST['food_time']),
             "food_content"=>$_POST['food_content'],
             "fcate_id"=>$_POST['fcate_id'],
         );

         if(isset($_POST['food_img']) && !empty($_POST['food_img']))
         {
             $data['food_img'] = $_POST['food_img'];
         }

         $affect_id = update("{$pre_}food",$data,"food_id = $food_id");
         if($affect_id)  //修改成功
         {
             echo json_encode(array(true));
             exit;
         }else{
             echo json_encode(array(false));
             exit;
         }


     }
 }else if($action == "food_delete"){
    
    $affect_id = delete("{$pre_}food","food_id = $food_id");

    if($affect_id){
        echo json_encode(array(true));
        exit;
    }else{
        echo json_encode(array(false));
        exit;
    }
 }else if($action=="catefood_count"){
    
     $sql = "SELECT COUNT(*) AS c FROM {$pre_}catefood";
      $article_count = getOne($sql);
      echo json_encode($article_count);
      exit;



 }else if($action=="catefood_list"){

     $start=($page-1)*$limit;
    $sql="SELECT * FROM {$pre_}catefood LIMIT $start , $limit";
    $catefood=getAll($sql);
    echo json_encode($catefood);
    exit();


 }else if($action=="catefood_add"){

  if($_POST){

  $data = array(

            "fcate_name"=>$_POST["fcate_name"],
            "fcate_time"=>strtotime($_POST['fcate_time']),
           
        );


   $insert_id = insert("{$pre_}catefood",$data);
        if($insert_id){
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }

  }



 }else if($action=="catefood_detile"){
 
  $sql="SELECT * FROM {$pre_}catefood WHERE fcate_id=$fcate_id";

  $catefood=getOne($sql);

  echo json_encode($catefood);

  exit();


 }else if($action=="catefood_edit"){


        if($_POST){
         $data = array(
            "fcate_name"=>$_POST['fcate_name'],
            "fcate_time"=>strtotime($_POST['fcate_time']),
          
        );

   $affect_id = update("{$pre_}catefood",$data,"fcate_id=$fcate_id");

     if($affect_id)  //修改成功
        {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }
    }

 }else if($action=="catefood_delete"){

    $affect_id = delete("{$pre_}catefood","fcate_id=$fcate_id");

    if($affect_id)
    {
        echo json_encode(array(true));
        exit;
    }else{
        echo json_encode(array(false));
        exit;
    }

 }else if($action=="article_count"){

      $sql = "SELECT COUNT(*) AS c FROM {$pre_}article";
      $article_count = getOne($sql);
      echo json_encode($article_count);
      exit;


 }else if($action=="article_cate"){  //文章添加的主类查询
       // 查出文章主类的所有
       
      $sql="SELECT * FROM {$pre_}article_cate";

      $article_list=getAll($sql);
      echo json_encode($article_list);
      exit();


 }else if($action=="article_list"){

     $start=($page-1)*$limit;
     $sql="SELECT * FROM {$pre_}article LIMIT $start,$limit";
     // 联表查询 查出所属分类
     $sql = "SELECT * FROM {$pre_}article AS a LEFT JOIN {$pre_}article_cate AS ac ON a.artcate_id = ac.artcate_id ORDER BY a.artcate_id DESC LIMIT $start,$limit";
      $article=getAll($sql);
      echo json_encode($article);
      exit();

 }else if($action == "article_add"){
    if($_FILES && $_FILES['file']['error'] == 0 && $food_img = upload_file("file","../Assets/uploads/")){
        echo json_encode(array("art_img"=>$food_img));
        exit;
    }
    // 通过  saveForm()方法提交过来的 数据
    if($_POST){
        $data = array(
            "art_title"=>$_POST['art_title'],
            "artcate_id"=>$_POST['artcate_id'],
            "art_time"=>strtotime($_POST['art_time']),
            "art_author"=>$_POST['art_author'],
            "art_desc"=>$_POST['art_desc'], 
            "art_content"=>$_POST['art_content'],
        );
        if(isset($_POST['art_img']) && !empty($_POST['art_img'])){
            $data['art_img'] = $_POST['art_img'];
        }

        $insert_id = insert("{$pre_}article",$data);
        if($insert_id)  //修改成功
        {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }


    }


}else if($action=="article_detail"){ //用于显示旧信息
   
   $sql="SELECT * FROM {$pre_}article AS a LEFT JOIN {$pre_}article_cate AS ac ON a.artcate_id=ac.artcate_id WHERE a.art_id=$art_id";
   
   $article_edite=getOne($sql);
   echo json_encode($article_edite);
   exit();

}else if($action=="article_edite"){
   
   if($_FILES && $_FILES['file']['error'] == 0 && $food_img = upload_file("file","../Assets/uploads/")){
        echo json_encode(array("art_img"=>$food_img));
        exit;
    }
    // 通过  saveForm()方法提交过来的 数据
    
    if($_POST){
        $data = array(
            "art_title"=>$_POST['art_title'],
            "artcate_id"=>$_POST['artcate_id'],
            "art_time"=>strtotime($_POST['art_time']),
            "art_author"=>$_POST['art_author'],
            "art_desc"=>$_POST['art_desc'], 
            "art_content"=>$_POST['art_content'],
        );

        if(isset($_POST['art_img']) && !empty($_POST['art_img'])){
            $data['art_img'] = $_POST['art_img'];
        }

        $affect_id = update("{$pre_}article",$data,"art_id = $art_id");


        if($insert_id)  //修改成功
        {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }


    }

}else if($action=="article_delete"){//用于删除 

 $affect_id = delete("{$pre_}article","art_id = $art_id");

    if($affect_id)
    {
        echo json_encode(array(true));
        exit;
    }else{
        echo json_encode(array(false));
        exit;
    }



}else if($action=="art_count"){
    
      $sql = "SELECT COUNT(*) AS c FROM {$pre_}article_cate";
      $food_count = getOne($sql);
      echo json_encode($food_count);
      exit;

}else if($action=="article_cate_list"){

    $start=($page-1)*$limit;
    $sql="SELECT * FROM {$pre_}article_cate LIMIT $start,$limit";
    $art=getAll($sql);
    echo json_encode($art);
    exit();

}else if($action=="article_cate_add"){
    
   if($_POST)
    {
        $data = array(

            "artcate_name"=>$_POST['artcate_name'],
          
        );
        $insert_id = insert("{$pre_}article_cate",$data);
        if($insert_id)  //修改成功
        {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }
    }
}else if($action=="article_cate_detail"){
 
    $sql="SELECT * FROM {$pre_}article_cate WHERE artcate_id=$artcate_id";
    $article=getOne($sql);

    echo json_encode($article);

    exit();
   
}else if($action=="article_cate_edite"){

 if($_POST){

         $data = array(


            "artcate_name"=>$_POST['artcate_name'],
          
        );
     $affect_id = update("{$pre_}article_cate",$data,"artcate_id=$artcate_id");
     if($affect_id)  //修改成功
        {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }


    }

}else if($action=="article_cate_delete"){

     $affect_id = delete("{$pre_}article_cate","artcate_id = $artcate_id");

    if($affect_id)
    {
        echo json_encode(array(true));
        exit;
    }else{
        echo json_encode(array(false));
        exit;
    }


}else if($action=="shop_count"){//店面管理

  $sql = "SELECT COUNT(*) AS c FROM {$pre_}shop";
  $food_count = getOne($sql);
  echo json_encode($food_count);
  exit;


}else if($action=="shop_list"){


  $start=($page-1)*$limit;
  $sql="SELECT * FROM {$pre_}shop as s LEFT JOIN {$pre_}region as r ON s.region_id=r.region_id WHERE s.shop_id LIMIT $start,$limit";
  $shop=getAll($sql);
  echo json_encode($shop);
  exit();

}else if($action=="region_cate"){
  
    $sql="SELECT * FROM {$pre_}region";
    $region=getAll($sql);
    echo json_encode($region);
    exit();
  
}else if($action=="shop_add"){
 
   // 图片提交
  if($_FILES && $_FILES['file']['error']==0 && $shop_img=upload_file("file","../Assets/uploads/")){

   echo json_encode(array("shop_img"=>$shop_img));
   exit();
  }

   // 如果是表单提交
   if($_POST){
      $data=array(
         "shop_name"=>$_POST["shop_name"],
         "region_id"=>$_POST["region_id"],
         "shop_address"=>$_POST["shop_address"],
         "shop_phone"=>$_POST["shop_phone"],
         "shop_fax"=>$_POST["shop_fax"],
         "shop_region"=>$_POST["shop_region"],
         "shop_time"=>strtotime($_POST["shop_time"]),
        );
      if(isset($_POST['shop_img'])&& !empty($_POST['shop_img'])){
         $data['shop_img']=$_POST['shop_img'];
      }
     $insert_id = insert("{$pre_}shop",$data);
        if($insert_id) {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        } 
   }

}else if($action=="shop_detile"){

  $sql="SELECT * FROM {$pre_}shop as s LEFT JOIN {$pre_}region as r ON s.region_id=r.region_id WHERE s.shop_id=$shop_id";
  $shop=getOne($sql);
  echo json_encode($shop);
  exit();

}else if($action=="shop_edit"){

   if($_FILES && $_FILES['file']['error']==0 && $shop_img=upload_file("file","../Assets/uploads/")){

   echo json_encode(array("shop_img"=>$shop_img));
   exit();
  }

   // 如果是表单提交
   if($_POST){
      $data=array(
         "shop_name"=>$_POST["shop_name"],
         "region_id"=>$_POST["region_id"],
         "shop_address"=>$_POST["shop_address"],
         "shop_phone"=>$_POST["shop_phone"],
         "shop_fax"=>$_POST["shop_fax"],
         "shop_region"=>$_POST["shop_region"],
         "shop_time"=>strtotime($_POST["shop_time"]),
        );
      if(isset($_POST['shop_img'])&& !empty($_POST['shop_img'])){
         $data['shop_img']=$_POST['shop_img'];
      }
     $insert_id = update("{$pre_}shop",$data,"shop_id=$shop_id");
        if($insert_id) {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        } 
   }


}else if($action=="shop_delete"){

      
    $affect_id = delete("{$pre_}shop","shop_id = $shop_id");

    if($affect_id)
    {
        echo json_encode(array(true));
        exit;
    }else{
        echo json_encode(array(false));
        exit;
    }

}else if($action=="region_count"){
      
      $sql = "SELECT COUNT(*) AS c FROM {$pre_}region";
      $food_count = getOne($sql);
      echo json_encode($food_count);
      exit;

}else if($action=="region_list"){

       $start=($page-1)*$limit;

      $sql="SELECT * FROM {$pre_}region LIMIT $start,$limit";
      $region=getAll($sql);
      echo json_encode($region);
      exit();


}else if($action=="region_add"){

      if($_POST){
       $data=array(
         "region_name"=>$_POST["region_name"]
        );
      }

    $insert_id = insert("{$pre_}region",$data);
        if($insert_id) {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }

}else if($action=="region_detail"){

       $sql="SELECT * FROM {$pre_}region WHERE region_id=$region_id";
       $region=getOne($sql);
       echo json_encode($region);
       exit();

}else if($action=="region_edit"){

     if($_POST){
         $data = array(

             "region_name"=>$_POST["region_name"], 

             );
         $affect_id = update("{$pre_}region",$data,"region_id = $region_id");
         if($affect_id)  //修改成功
         {
             echo json_encode(array(true));
             exit;
         }else{
             echo json_encode(array(false));
             exit;
         }


     }

}else if($action=="region_delete"){

  $affect_id = delete("{$pre_}region","region_id = $region_id");

    if($affect_id)
    {
        echo json_encode(array(true));
        exit;
    }else{
        echo json_encode(array(false));
        exit;
    }

}else if($action=="link_count"){
   
      $sql = "SELECT COUNT(*) AS c FROM {$pre_}link";
      $food_count = getOne($sql);
      echo json_encode($food_count);
      exit;

}else if($action=="link_list"){

    $start = ($page-1)*$limit;
    $sql = "SELECT * FROM {$pre_}link LIMIT $start,$limit";
    $link_list = getAll($sql);
    echo json_encode($link_list);
    exit;

}else if($action=="link_add"){
   

   // uploadImg提交的数据

    if($_FILES && $_FILES['file']['error'] == 0 && $link_img = upload_file("file","../Assets/uploads/")){
        echo json_encode(array("link_img"=>$link_img));
        exit;
    }


    // saveForm 提交数据


   if($_POST){
        $data = array(

            "link_name"=>$_POST['link_name'],
            "link_url"=>$_POST['link_url'],
            "link_order"=>$_POST['link_order'],
          
        );

        if(isset($_POST['link_img']) && !empty($_POST['link_img']))
        {
            $data['link_img'] = $_POST['link_img'];
        }

        $insert_id = insert("{$pre_}link",$data);
        if($insert_id) {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }
    }
}else if($action=="link_detail"){

  $sql="SELECT * FROM {$pre_}link WHERE link_id=$link_id";
  $link=getOne($sql);
  echo json_encode($link);
  exit();

}else if($action=="link_edite"){
   
    // uploadImg提交的数据

    if($_FILES && $_FILES['file']['error'] == 0 && $link_img = upload_file("file","../Assets/uploads/")){
        echo json_encode(array("link_img"=>$link_img));
        exit;
    }


    // saveForm 提交数据


   if($_POST){
        $data = array(

            "link_name"=>$_POST['link_name'],
            "link_url"=>$_POST['link_url'],
            "link_order"=>$_POST['link_order'],
          
        );

        if(isset($_POST['link_img']) && !empty($_POST['link_img']))
        {
            $data['link_img'] = $_POST['link_img'];
        }

        $insert_id = update("{$pre_}link",$data,"link_id=$link_id");
        if($insert_id) {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }
    }
}else if($action=="link_delete"){
   $affect_id = delete("{$pre_}link","link_id = $link_id");
    if($affect_id){
        echo json_encode(array(true));
        exit;
    }else{
        echo json_encode(array(false));
        exit;
    }
}else if($action=="company_count"){

      $sql = "SELECT COUNT(*) AS c FROM {$pre_}company";
      $company_count = getOne($sql);
      echo json_encode($company_count);
      exit;

}else if($action=="company_list"){
    
    $start = ($page-1)*$limit;

    $sql = "SELECT * FROM {$pre_}company LIMIT $start,$limit";

    $company_list = getAll($sql);
    echo json_encode($company_list);
    exit;
    
}else if($action=="company_add"){

   if($_FILES && $_FILES['file']['error'] == 0 && $company_img = upload_file("file","../Assets/uploads/")){
        
        echo json_encode(array("company_img"=>$company_img));
        exit;
    }

    if($_POST){
        $data = array(
            "company_name"=>$_POST['company_name'],
            "company_phone"=>$_POST['company_phone'],
            "company_time"=>strtotime($_POST['company_time']),
            "company_fax"=>$_POST['company_fax'],
            "company_address"=>$_POST['company_address'],
            "company_postal"=>$_POST['company_postal'],

        );

        if(isset($_POST['company_img']) && !empty($_POST['company_img'])){
            $data['company_img'] = $_POST['company_img'];
        }

        $insert_id = insert("{$pre_}company",$data);
        if($insert_id) {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }


    }

}else if($action=="company_detail"){

   $sql="SELECT * FROM {$pre_}company WHERE company_id=$company_id";
   $company=getOne($sql);
   echo json_encode($company);
   exit();

  
}else if($action=="company_edite"){

  if($_FILES && $_FILES['file']['error'] == 0 && $company_img = upload_file("file","../Assets/uploads/")){
        
        echo json_encode(array("company_img"=>$company_img));
        exit;
    }

    if($_POST){
        $data = array(
            "company_name"=>$_POST['company_name'],
            "company_phone"=>$_POST['company_phone'],
            "company_time"=>strtotime($_POST['company_time']),
            "company_fax"=>$_POST['company_fax'],
            "company_address"=>$_POST['company_address'],
            "company_postal"=>$_POST['company_postal'],

        );

        if(isset($_POST['company_img']) && !empty($_POST['company_img'])){
            $data['company_img'] = $_POST['company_img'];
        }

        $insert_id = insert("{$pre_}company",$data);
        if($insert_id) {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }


    }
}else if($action=="company_delete"){


 $affect_id = delete("{$pre_}company","company_id = $company_id");

    if($affect_id)
    {
        echo json_encode(array(true));
        exit;
    }else{
        echo json_encode(array(false));
        exit;
    }

}else if($action=="admin_count"){

      $sql = "SELECT COUNT(*) AS c FROM {$pre_}admin";
      $food_count = getOne($sql);
      echo json_encode($food_count);
      exit;


}else if($action=="admin_list"){
     
     $start=($page-1)*$limit;
     $sql="SELECT * FROM {$pre_}admin LIMIT $start,$limit";
     $admin_list=getAll($sql);
     echo json_encode($admin_list);
     exit();



}else if($action=="admin_add"){
  
  // 如果提交过来的是一张图片
  if($_FILES && $_FILES['file']['error'] == 0 && $admin_img = upload_file("file","../Assets/uploads/"))
    {
        echo json_encode(array("admin_img"=>$admin_img));
        exit;
    }

  // 如果提交的是数据
      if($_POST){
        $data = array(
          
            "admin_name"=>$_POST['admin_name'],
            "admin_pwd"=>md5($_POST['admin_pwd']),
            "admin_time"=>strtotime($_POST['admin_time']),
        );

        if(isset($_POST['admin_img']) && !empty($_POST['admin_img']))
        {
            $data['admin_img'] = $_POST['admin_img'];
        }

        $insert_id = insert("{$pre_}admin",$data);

        if($insert_id) {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }


    }
    
}else if($action=="admin_detail"){
   $sql="SELECT * FROM {$pre_}admin WHERE admin_id=$admin_id";
   $admin=getOne($sql);
   echo json_encode($admin);
   exit();

}else if($action=="admin_edite"){
   
    // 如果提交过来的是一张图片
  if($_FILES && $_FILES['file']['error'] == 0 && $admin_img = upload_file("file","../Assets/uploads/"))
    {
        echo json_encode(array("admin_img"=>$admin_img));
        exit;
    }

  // 如果提交的是数据
      if($_POST){
        $data = array(
          
            "admin_name"=>$_POST['admin_name'],
            "admin_pwd"=>md5($_POST['admin_pwd']),
            "admin_time"=>strtotime($_POST['admin_time']),
        );

        if(isset($_POST['admin_img']) && !empty($_POST['admin_img']))
        {
            $data['admin_img'] = $_POST['admin_img'];
        }

        $insert_id = update("{$pre_}admin",$data,"admin_id=$admin_id");

        if($insert_id) {
            echo json_encode(array(true));
            exit;
        }else{
            echo json_encode(array(false));
            exit;
        }


    }
    

}else if($action=="admin_delete"){

    $affect_id=delete("{$pre_}admin","admin_id=$admin_id");

      if($affect_id)
    {
        echo json_encode(array(true));
        exit;
    }else{
        echo json_encode(array(false));
        exit;
    }


    

}else if($action=="admin_action"){
       $sql="SELECT * FROM {$pre_}admin_action";
       $admin=getAll($sql);
       echo json_encode($admin);
       exit;


}else if($action == "login"){
  
       if($_POST){

            $admin_name = isset($_POST['admin_name']) ? $_POST['admin_name'] : "";
            $admin_pwd = isset($_POST['admin_pwd']) ? $_POST['admin_pwd'] : "";

            $admin_pwd = md5($admin_pwd);

            $sql = "SELECT * FROM {$pre_}admin WHERE admin_name = '$admin_name' AND admin_pwd = '$admin_pwd'";
            $admin_info = getOne($sql);
            echo json_encode($admin_info);
            exit;
       }
 }


?>